from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import datetime

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:123456@127.0.0.1:3306/f1"
# 如果设置成 True (默认情况)，Flask-SQLAlchemy 将会追踪对象的修改并且发送信号。
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True

# 绑定app至SQLAlchemy
db = SQLAlchemy(app)



#会员模型
class User(db.Model):

    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(100),unique=True)
    pwd= db.Column(db.String(100))
    email= db.Column(db.String(100))
    phone= db.Column(db.String(11))
    # info= db.Column(db.Text)
    # face = db.Column(db.String(255))
    addtime = db.Column(db.DateTime,default=datetime.datetime.now)

    def __repr__(self):
        return '<User %r>' % self.name

if __name__ == "__main__":
    pass
    # 创建生产表
    # db.create_all()
    # 添加数据
    # data = {'name':'李四','pwd':'123','email':'q@q','phone':'123'}
    # ob = User(**data)

    # 把对象添加到对象中
    # db.session.add(ob)
    # db.session.commit()


    # 获取
    # ob = User.query.get(2)

    # 删除
    # db.session.delete(ob)
    # db.session.commit()
    # print(ob)
    # print(ob.name)

    # 修改
    # ob.name = '牛二'
    # db.session.add(ob)
    # db.session.commit()